//
//  topView.swift
//  MySinaWeiBo
//
//  Created by zhangfuwei on 15/8/3.
//  Copyright © 2015年 zhangfuwei. All rights reserved.
//
///// 用户代号
//var id: Int = 0
///// 友好显示名称
//var name: String?
///// 用户头像地址（中图），50×50像素
//var profile_image_url: String? {
//didSet {
//    imageURL = NSURL(string: profile_image_url!)
//}
//}
//
///// 头像 URL
//var imageURL: NSURL?
//
///// 用户的认证类型，-1：没有认证，0，认证用户，2,3,5: 企业认证，220: 达人
//var verified_type: Int = -1
///// 认证图标
//var vipImage: UIImage? {
//    switch verified_type {
//        
//    case 0: return UIImage(named: "avatar_vip")
//    case 2, 3, 5: return UIImage(named: "avatar_enterprise_vip")
//    case 220: return UIImage(named: "avatar_grassroot")
//    default: return nil
//    }
//}
//
///// 会员等级 1~6
//var mbrank: Int = -1
///// 会员图像
//var memberImage: UIImage



import UIKit

class topView: UIView {

    var status:Status? {
        didSet {
            
            nameLbl.text = status?.user?.name
//            sourceLbl.text = status?.source
            vipView.image = status?.user?.memberImage
            verifiedtypeView.image = status?.user?.verifiedImage
            
            // TODO: 
            
            timeLbl.text = "刚刚"
            sourceLbl.text = "来自微博"
            iconView.sd_setImageWithURL(status?.user?.imageURL)
            
        }
    }
    ///  重写指定构造函数
    override  init(frame: CGRect) {
        super.init(frame: frame)
        prepareTopview()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    ///  准备顶部视图
    func prepareTopview() {
        backgroundColor = UIColor.clearColor()
        
        addSubview(iconView)
        addSubview(nameLbl)
        addSubview(timeLbl)
        addSubview(sourceLbl)
         addSubview(vipView)
        addSubview(verifiedtypeView)
        ///  设置约束
       
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 10 , y: 10))
        nameLbl.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 10, y: 0))
        timeLbl.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: nameLbl, size: nil, offset: CGPoint(x: 0, y: 0))
        sourceLbl.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLbl, size: nil, offset: CGPoint(x: 10, y: 0))
        vipView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLbl, size: nil, offset: CGPoint(x: 10, y: 0))
        
        verifiedtypeView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x:verifiedtypeView.bounds.size.height * 0.5, y: verifiedtypeView.bounds.size.height * 0.5))
    }
    
    // MARK: 懒加载控件
    
    lazy var iconView : UIImageView = UIImageView(image: UIImage(named: "avatar"))
    lazy var nameLbl :UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 16)
    
    lazy var timeLbl : UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 12)
    
     lazy var sourceLbl : UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 12)
    
    lazy var verifiedtypeView : UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))
    lazy var vipView : UIImageView = UIImageView(image:UIImage(named: "avatar_vip"))

}
